package com.study.ex;

import com.study.controller.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : wilbur.yuan
 * @date : 2018-11-21
 */
@Slf4j
@RestControllerAdvice
public class ExceptionResolver {

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler({CheckException.class,MissingServletRequestParameterException.class})
    public Result checkException(Exception e) {
        return Result.error(-1, e.getMessage());
    }

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        log.error("rankings webapp error: ", e);
        return Result.error(-1, "");
    }

}
